<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Floor View</title>
<script src="/js/websocket.js"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/sockjs.min.js"></script>
<script src="/js/stomp.min.js"></script>
<script id="code">
    var DEBUG_FLAG = true;
    $(function()
    {
        //启动websocket
        connect();
    });

    function sendToAll() {
      var msg = $("#msg").val();
      stompClient.send("/app/sendToAll", {}, msg);
    }

    function sendToUser() {
      var msg = $("#msg").val();
      var toUserId = $("#userId").val();
      var data  = {"fromUserId": userId, "toUserId": toUserId, "msg": msg};
      stompClient.send("/app/sendToUser", {}, JSON.stringify(data));
    }

    function logout() {
      var storage=window.localStorage;
      storage.setItem("token", "");
      window.location.href = "/login.html";
    }

    function testToken() {
      var storage=window.localStorage;
      var token = storage.getItem("token");
      $.ajax({
        async: false,
        type: "POST",
        url: '/user/list',
        headers: {
          'Authorization': token
        },
        success: function (result) {
          console.log(result)
          alert(result);
        }
      });
    }
</script>
</head>

<body style="margin: 0px;padding: 0px;overflow: hidden; ">
  <!-- 显示消息-->
  <textarea id="debuggerInfo" style="width:100%;height:200px;"></textarea>
  <!-- 发送消息-->
  <div>用户：<input type="text" id="userId"></input></div>
  <div>消息：<input type="text" id="msg"></input></div>
  <div><input type="button" value="点对点发送消息" onclick="sendToUser()"></input></div>
  <div><input type="button" value="群发送消息" onclick="sendToAll()"></input></div>
  <div><input type="button" value="退出登录" onclick="logout()"></input></div>
  <div><input type="button" value="接试接口访问" onclick="testToken()"></input></div>
</body>
</html>